package com.fr.chart.core.glyph;

import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import java.awt.Graphics;
import java.awt.geom.Arc2D.Double;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

public class AreaPlotGlyph extends CategoryPlotGlyph
{
  private static final long serialVersionUID = -8812027062679027417L;
  public static final String XML_TAG = "AreaPlotGlyph";

  public void layoutDataSeriesGlyph()
  {
    for (int i = 0; i < getSeriesSize(); ++i)
    {
      DataSeries localDataSeries = getSeries(i);
      int j = 0;
      for (int k = 0; k < localDataSeries.getDataPointCount(); ++k)
        if (!(localDataSeries.getDataPoint(k).isValueIsNull()))
          ++j;
      double[] arrayOfDouble1 = new double[j];
      double[] arrayOfDouble2 = new double[j];
      j = 0;
      GeneralPath localGeneralPath = new GeneralPath(1);
      ShapeGlyph localShapeGlyph = new ShapeGlyph(localGeneralPath);
      localDataSeries.setDrawImpl(localShapeGlyph);
      localShapeGlyph.getInfo().dealCondition(getSeriesCollection(), i);
      double[] arrayOfDouble3 = new double[localDataSeries.getDataPointCount()];
      float f1 = (float)getCategoryAxisGlyph().getPoint2DCateAxis(0.0D, 0.0D).getX();
      float f2 = (float)getValueAxisGlyph().getPoint2D(0.0D).getY();
      float f3 = (float)getValueAxisGlyph().getPoint2D(0.0D).getY();
      localGeneralPath.moveTo(f1, f2);
      for (int l = 0; l < localDataSeries.getDataPointCount(); ++l)
      {
        DataPoint localDataPoint = localDataSeries.getDataPoint(l);
        double d1 = getDataPointPercentValue(i, l);
        if (isStacked())
        {
          f1 = (float)getCategoryAxisGlyph().getPoint2DCateAxis(l, 0.0D).getX();
          double d2 = 0.0D;
          for (int i3 = i - 1; i3 >= 0; --i3)
            d2 += getDataPointPercentValue(i3, l);
          f2 = (float)(getValueAxisGlyph().getBounds().getY() + (float)getValueAxisGlyph().getPoint2D(d2 + d1).getY());
          arrayOfDouble3[l] = (getValueAxisGlyph().getBounds().getY() + (float)getValueAxisGlyph().getPoint2D(d2).getY());
        }
        else
        {
          if (localDataPoint.isValueIsNull())
          {
            if (!(isNullValueBreak()))
              break label530:
            if (l > 0)
              localGeneralPath.lineTo((float)getCategoryAxisGlyph().getPoint2DCateAxis(l - 1, 0.0D).getX(), f3);
            localGeneralPath.lineTo((float)getCategoryAxisGlyph().getPoint2DCateAxis(l, 0.0D).getX(), f3);
            if (l >= localDataSeries.getDataPointCount())
              break label530;
            localGeneralPath.lineTo((float)getCategoryAxisGlyph().getPoint2DCateAxis(l + 1, 0.0D).getX(), f3);
            break label530:
          }
          f1 = (float)getCategoryAxisGlyph().getPoint2DCateAxis(l, 0.0D).getX();
          f2 = (float)(getValueAxisGlyph().getBounds().getY() + (float)getValueAxisGlyph().getPoint2D(d1).getY());
          arrayOfDouble1[j] = f1;
          arrayOfDouble2[j] = f2;
          ++j;
        }
        localGeneralPath.lineTo(f1, f2);
        localDataPoint.setShape(new Arc2D.Double(f1 - 3.0F, f2 - 3.0F, 6.0D, 6.0D, 0.0D, 360.0D, 2));
        dealDataPointLabelBounds(localDataPoint, i);
      }
      if (isStacked())
      {
        int i1 = arrayOfDouble3.length - 1;
        while (true)
        {
          if (i1 < 0)
            break label628;
          localGeneralPath.lineTo((float)getCategoryAxisGlyph().getPoint2DCateAxis(i1, 0.0D).getX(), (float)arrayOfDouble3[i1]);
          --i1;
        }
      }
      for (int i2 = localDataSeries.getDataPointCount() - 1; i2 >= 0; --i2)
        localGeneralPath.lineTo((float)getCategoryAxisGlyph().getPoint2DCateAxis(i2, 0.0D).getX(), f3);
      if (!(isStacked()))
        trendLineFitting(arrayOfDouble1, arrayOfDouble2, i);
    }
    label530: label628: return;
  }

  public void draw(Graphics paramGraphics)
  {
    drawInfo(paramGraphics);
    super.draw(paramGraphics);
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("AreaPlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof AreaPlotGlyph))
      return false;
    AreaPlotGlyph localAreaPlotGlyph = (AreaPlotGlyph)paramObject;
    return (super.equals(localAreaPlotGlyph));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    AreaPlotGlyph localAreaPlotGlyph = (AreaPlotGlyph)super.clone();
    return localAreaPlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    return localJSONObject;
  }

  public String getPlotGlyphType()
  {
    return "AreaPlotGlyph";
  }
}